
package com.pengshun.modules.api.coal.service.impl;
import com.pengshun.modules.api.coal.repository.ProblemRepository;
import com.pengshun.modules.api.coal.repository.ProblemTypeRepository;
import com.pengshun.modules.api.coal.service.ProblemService;
import com.pengshun.modules.api.coal.service.dto.ProblemDto;
import com.pengshun.modules.api.coal.service.mapstruct.ProblemMapper;
import com.pengshun.modules.api.mapper.PsMerchantMapper;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.Problem;
import com.pengshun.modules.domain.ProblemType;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author lifei
* @date 2020-11-13
**/
@Service
@RequiredArgsConstructor
public class ProblemServiceImpl implements ProblemService {

    private final ProblemRepository problemRepository;
    private final ProblemTypeRepository problemTypeRepository;
    private final PsMerchantMapper psMerchantMapper;

    @Override
    public BaseResult selectAllProblemType() {
        List<ProblemType>  list=problemTypeRepository.findAllByEnabledOrderBySort(1);
        return new BaseResult(0,list);
    }

    @Override
    public BaseResult findByProblemTypeId(Integer problemTypeId) {
        List<ProblemDto> list=psMerchantMapper.findByProblemTypeId(problemTypeId);
        return new BaseResult(0,list);
    }

    @Override
    public BaseResult findByProblemDetil(Long id) {
        Problem problem=problemRepository.findById(id).orElseGet(Problem::new);
        return new BaseResult(0,problem);
    }


}